package cn.com.ddapp.ddm.ui;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.hdos.usbdevice.publicSecurityIDCardLib;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import cn.com.ddapp.ddm.AppConfig;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.adapter.UrgentDayAdpter;
import cn.com.ddapp.ddm.adapter.UrgentTimeAdpter;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.base.ActivityManager;
import cn.com.ddapp.ddm.base.BaseActivity;
import cn.com.ddapp.ddm.base.BaseApplication;
import cn.com.ddapp.ddm.bean.AddressBean;
import cn.com.ddapp.ddm.bean.Coupons;
import cn.com.ddapp.ddm.bean.CouponsEntity;
import cn.com.ddapp.ddm.bean.Entity;
import cn.com.ddapp.ddm.bean.mine.UserData;
import cn.com.ddapp.ddm.bean.settleShopcar.Accept;
import cn.com.ddapp.ddm.bean.settleShopcar.SettleAccountsEntity;
import cn.com.ddapp.ddm.bean.settleShopcar.SettleGoods;
import cn.com.ddapp.ddm.bean.settleShopcar.SettleShopGoodsCar;
import cn.com.ddapp.ddm.inter.OkUtilCallback;
import cn.com.ddapp.ddm.ui.empty.EmptyLayout;
import cn.com.ddapp.ddm.ui.mine.AddAddressActivity;
import cn.com.ddapp.ddm.ui.mine.AddressActivity;
import cn.com.ddapp.ddm.ui.order.PayActivity;
import cn.com.ddapp.ddm.util.JsonHttpNet;
import cn.com.ddapp.ddm.util.NetUtils;
import cn.com.ddapp.ddm.util.SPUtils;
import cn.com.ddapp.ddm.util.StringUtils;
import cn.com.ddapp.ddm.util.TDevice;
import cn.com.ddapp.ddm.util.TLog;
import cn.com.ddapp.ddm.widget.TipsToast;
import okhttp3.Call;

/**
 * Created by Administrator on 2016/8/25 0025.单个商品立即购买
 */
public class AtOneBuyActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.action)
    TextView action;
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.listview)
    ListView listview;
    @BindView(R.id.accepter)
    TextView accepterTextView;
    @BindView(R.id.tel)
    TextView telTextView;
    @BindView(R.id.address)
    TextView addressTextView;
    @BindView(R.id.commit_order)
    TextView mCommitOrder;
    @BindView(R.id.error_layout)
    EmptyLayout mEmptyLayout;
    @BindView(R.id.accpetNone)
    RelativeLayout mAccpetNone;
    @BindView(R.id.acceptLinearlayout)
    LinearLayout mAcceptLinearlayout;
    @BindView(R.id.total_account)//订单总计
            TextView totalAccount;
    @BindView(R.id.vipTextView)
    TextView vipTextView;
    @BindView(R.id.vipMoneyAmount)
    TextView vipMoneyAmount;//加急邮费
    @BindView(R.id.why)
    TextView why;
    @BindView(R.id.vip)
    CheckBox vip;
    @BindView(R.id.vipLinearLayout)
    LinearLayout vipLinearLayout;
    @BindView(R.id.couponRelative)
    RelativeLayout couponRelative;
    @BindView(R.id.buyerTipsEditText)
    EditText mBuyerTips;//买家留言
    @BindView(R.id.select_urgent)
    RelativeLayout select_urgent;
    @BindView(R.id.vipMoney)
    TextView vipMoney;//加急邮费
    @BindView(R.id.toTime)
    TextView toTime;//送达时间

    public static final int REQ_CODE = 0x01;
    private String goodprice, goodname, id;
    private Accept accept;
    private SettleAccountsEntity settleAccountsEntity;
    private List<SettleGoods> settleGoodsList = new ArrayList<>();
    private List<SettleShopGoodsCar> settleShopGoodsCars;
    private Integer couponId;//要提交的优惠券ID

    private String getActivityTag() {
        return AtOneBuyActivity.class.getSimpleName();
    }

    private List<Coupons> couponsList = new ArrayList<Coupons>();
    private String userId;
    private String[] weeks = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
    private String[] times = {"8:00-10:00", "10:00-12:00", "12:00-14:00", "14:00-16:00", "16:00-18:00", "18:00-20:00"};
    private ListView urgent_day;
    private ListView urgent_hour;
    List<String> dayList = new ArrayList<>();
    List<String> timeList = new ArrayList<>();
    List<String> latertimeList = new ArrayList<>();
    private String seleDay, seleTime, tomorrow, acquired, afterTomorrow;
    private String refId;
    private String curTime;
    private String defautId;
    Dialog tdialog;
    private String seHour, seDay, postageMoney, ispost;
    private byte[] sex = new byte[6];
    private byte[] name = new byte[32];
    private byte[] birth = new byte[18];
    private byte[] nation = new byte[12];
    private byte[] address = new byte[72];
    private byte[] Department = new byte[32];
    private byte[] IDNo = new byte[38];
    private byte[] EffectDate = new byte[18];
    private byte[] ExpireDate = new byte[18];
    byte[] BmpFile = new byte[38556];
    private publicSecurityIDCardLib iDCardDevice;
    private Handler mHandler;
    boolean isstop = false;
    private String pkName;
    EditText nameEdit;
    EditText idCardEdit;
    Dialog dialog;

    @Override
    public void initView() {
        pkName = this.getPackageName();
        title.setText(BaseApplication.getIntstance().getResources().getString(R.string.sure_order));
        action.setVisibility(View.GONE);
        back.setVisibility(View.VISIBLE);
        back.setOnClickListener(this);
        mCommitOrder.setOnClickListener(this);
        mAccpetNone.setOnClickListener(this);
        couponRelative.setOnClickListener(this);
        select_urgent.setOnClickListener(this);
        goodprice = getIntent().getStringExtra("goodprice");
        goodname = getIntent().getStringExtra("goodname");
        id = getIntent().getStringExtra("goodid");
//        Log.i("aaa","---"+goodname+"--"+id+"---"+goodprice);

        refId = SPUtils.getStringData(AtOneBuyActivity.this, SPUtils.REFID);
        mAcceptLinearlayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(getApplicationContext(), AddressActivity.class);
                intent.putExtra("flag", "orderSure");
                startActivityForResult(intent, REQ_CODE);
            }
        });

        vipTextView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        why.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        vip.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (TextUtils.isEmpty(accepterTextView.getText().toString())) {
                    Toast.makeText(mContext, "请选择地址", Toast.LENGTH_SHORT).show();
                    vip.setChecked(false);
                } else {
                    if (isChecked) {
                        vipLinearLayout.setVisibility(View.VISIBLE);
                    } else {
                        vipLinearLayout.setVisibility(View.GONE);
                        toTime.setText("送达时间:");
                        vipMoney.setText("加急邮费:");
                        totalAccount.setText((NetUtils.setDecimal(AppConfig.SP_PRICE1 * AppConfig.TEMP)));
                    }
                }
            }
        });
        if (TDevice.isTablet(getApplicationContext())) {
            HandlerThread handlerThread = new HandlerThread("MyHandlerThread");
            handlerThread.start();
            mHandler = new Handler(handlerThread.getLooper(), new Handler.Callback() {
                @Override
                public boolean handleMessage(Message message) {
                    switch (message.what) {
                        case 1001:
                            if (!isstop) {
                                mHandler.post(getdata);
                            }
                            break;
                        case 1002:
                            mHandler.removeCallbacks(getdata);
                            break;
                    }
                    return false;
                }
            });
        }
    }

    @Override
    public void initData() {
        userId = SPUtils.getStringData(AtOneBuyActivity.this, SPUtils.USERID);
        getDefaultAdd();
//        final String address = OKUtilAPI.baseUrl + OKUtilAPI.ShouAddress + "?userId=" + userId;
//        if (!NetUtils.isConnected(this)) {
//            Toast.makeText(AtOneBuyActivity.this, "检查网络连接", Toast.LENGTH_SHORT).show();
//        } else {
//            JsonHttpNet.dataDownNet(address, new JsonHttpNet.HttpCallbackListener() {
//                @Override
//                public void onFinish(String response) {
//                    AddressBean addressBean = gson.fromJson(response, AddressBean.class);
//                    if (AppConfig.RESULT_OK.equalsIgnoreCase(addressBean.getResult())) {
//                        List<AddressBean.ListBean> list = addressBean.getList();
//                        addCommid(list);//添加收货地址
//                    } else {
//                        Toast.makeText(AtOneBuyActivity.this, addressBean.getResult(), Toast.LENGTH_SHORT).show();
//                    }
//                }
//
//                @Override
//                public void onError(Exception e) {
//
//                }
//            });
//        }
        listview.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return 1;
            }

            @Override
            public Object getItem(int i) {
                return null;
            }

            @Override
            public long getItemId(int i) {
                return 0;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup viewGroup) {
                ViewHolder holder = null;
                if (convertView == null) {
                    convertView = LayoutInflater.from(AtOneBuyActivity.this).inflate(R.layout.order_sure_item, null);
                    holder = new ViewHolder(convertView);
                    convertView.setTag(holder);
                } else {
                    holder = (ViewHolder) convertView.getTag();
                }
                Glide.with(AtOneBuyActivity.this).load(OKUtilAPI.imgBaseUrl + AppConfig.IMAGE_URL).into(holder.gLogo);
                holder.gName.setText(AppConfig.SP_NAME);
//                holder.sName.setText(goods.getShopName());
//                if (AppConfig.TEMP < 10) {
//                    holder.gPrice.setText("￥" + AppConfig.SP_PRICE);
//                } else {
//                }
                holder.gPrice.setText("￥" + goodprice);
                holder.gNum.setText("x" + AppConfig.TEMP + "");
                return convertView;
            }


            class ViewHolder {
                LinearLayout shopLinearlayout;
                TextView sName;
                ImageView gLogo;
                TextView gName;
                TextView gPrice;
                TextView gNum;

                public ViewHolder(View view) {
                    shopLinearlayout = (LinearLayout) view.findViewById(R.id.shop_linearlayout);
                    sName = (TextView) view.findViewById(R.id.sName);
                    gName = (TextView) view.findViewById(R.id.gName);
                    gPrice = (TextView) view.findViewById(R.id.gPrice);
                    gNum = (TextView) view.findViewById(R.id.gNum);
                    gLogo = (ImageView) view.findViewById(R.id.gLogo);
                }
            }
        });


        postageMoney = (NetUtils.setDecimal(AppConfig.SP_PRICE1 * AppConfig.TEMP));
        totalAccount.setText(postageMoney);
    }

    private void getDefaultAdd() {
        String params = "userId=" + userId;
        OKUtilAPI.post(OKUtilAPI.getDefAdd, params, new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                SettleAccountsEntity addressBean = gson.fromJson(response, SettleAccountsEntity.class);
                if (AppConfig.RESULT_OK.equalsIgnoreCase(addressBean.getResult())) {
//                        List<AddressBean.ListBean> list = addressBean.getList();
//                        addCommid(list);
                    //添加收货地址
                    if (addressBean.getAccept() == null) {
                        accepterTextView.setVisibility(View.GONE);
                        telTextView.setVisibility(View.GONE);
                        addressTextView.setText("暂无添加地址");
                    } else {
                        Accept address = addressBean.getAccept();
                        defautId = address.getCityId() + "";
                        accepterTextView.setVisibility(View.VISIBLE);
                        telTextView.setVisibility(View.VISIBLE);
                        accepterTextView.setText(address.getName());
                        telTextView.setText(address.getPhone());
                        addressTextView.setText(address.getProvince() + address.getCity() + address.getCounty() + address.getAddress());
                        Log.i("aaa", "---cityId--" + defautId);
                    }
                } else {
                    Toast.makeText(AtOneBuyActivity.this, addressBean.getResult(), Toast.LENGTH_SHORT).show();
                    accepterTextView.setVisibility(View.GONE);
                    telTextView.setVisibility(View.GONE);
                    addressTextView.setText("暂无添加地址");
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
            }
        });
    }

    private void addCommid(List<AddressBean.ListBean> list) {
        if (list.size() == 0) {
            mAccpetNone.setVisibility(View.VISIBLE);
            mAcceptLinearlayout.setVisibility(View.GONE);
        } else {
            mAccpetNone.setVisibility(View.GONE);
            mAcceptLinearlayout.setVisibility(View.VISIBLE);
            for (int a = 0; a < list.size(); a++) {
                Log.i("aaa", "--pp--" + list.get(a).getIsSelect());
                if (list.get(a).getIsSelect() == 1) {
                    accepterTextView.setVisibility(View.VISIBLE);
                    telTextView.setVisibility(View.VISIBLE);
                    accepterTextView.setText(list.get(a).getName());
                    telTextView.setText(list.get(a).getPhone());
                    addressTextView.setText(list.get(a).getProvince() + list.get(a).getCity() + list.get(a).getCounty() + list.get(a).getAddress());
                    return;
                } else {
//                    accepterTextView.setText(list.get(0).getName());
//                    telTextView.setText(list.get(0).getPhone());
//                    addressTextView.setText(list.get(0).getProvince() + list.get(0).getCity() + list.get(0).getCounty() + list.get(0).getAddress());
                    accepterTextView.setVisibility(View.GONE);
                    telTextView.setVisibility(View.GONE);
                    addressTextView.setText("暂无添加地址");

                }
            }

        }
    }

    @Override
    public int getContentViewId() {
        return R.layout.order_sure_activity;
    }

    @Override
    protected String getFragmentTag() {
        return null;
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == back.getId()) {
            ActivityManager.getInstance().finishActivity();
        } else if (v.getId() == mCommitOrder.getId()) {
            if (TextUtils.isEmpty(accepterTextView.getText().toString())) {
                Toast.makeText(AtOneBuyActivity.this, "请先选择收货地址", Toast.LENGTH_SHORT).show();
            } else {
                commitOrder();//提交订单
            }
        } else if (mAccpetNone.getId() == v.getId()) {
            Intent intent = new Intent(AtOneBuyActivity.this, AddAddressActivity.class);
            intent.putExtra("flag", "orderSure");
            startActivityForResult(intent, REQ_CODE);
        } else if (v.getId() == couponRelative.getId()) {
            toShowCoupon();
        } else if (v.getId() == select_urgent.getId()) {
            toshowTime();
        }

    }

    //加急邮费的时间选择
    private void toshowTime() {
        tdialog = new Dialog(AtOneBuyActivity.this, R.style.Transparent);
        tdialog.setContentView(R.layout.urgent_time);
        urgent_day = (ListView) tdialog.findViewById(R.id.urgent_day);
        urgent_hour = (ListView) tdialog.findViewById(R.id.urgent_hour);
        showWeek();

        tdialog.setCanceledOnTouchOutside(true);
        Window win = tdialog.getWindow();
        win.setGravity(Gravity.BOTTOM);
        win.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.FILL_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
        lp.dimAmount = 0.5f;
        win.setAttributes(lp);
        tdialog.show();
    }

    private void showWeek() {
        dayList.clear();
        timeList.clear();
        latertimeList.clear();
        long time = System.currentTimeMillis();
        Date date = new Date(time);
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 EEEE");
        format = new SimpleDateFormat("EEEE");
        String curWeek = format.format(date);
        format = new SimpleDateFormat("HH");
        curTime = format.format(date);
        format = new SimpleDateFormat("yyyy-MM-dd");


        seleDay = format.format(date);

        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, +1);
        format.format(c.getTime());

        Calendar d = Calendar.getInstance();
        d.add(Calendar.DAY_OF_MONTH, +2);
        format.format(d.getTime());

        Calendar e = Calendar.getInstance();
        e.add(Calendar.DAY_OF_MONTH, +3);
        format.format(d.getTime());

        tomorrow = format.format(c.getTime()); //明天
        acquired = format.format(d.getTime());  //后天
        afterTomorrow = format.format(e.getTime());  //大后天

        Log.i("aaa", "---" + seleDay + "--1-" + tomorrow + "--2--" + acquired + "--curTime--" + curTime);
        if (Integer.parseInt(curTime) >= 16) {
            if (curWeek.equals("星期日")) {
                dayList.add("明天(" + weeks[1] + ")");
                dayList.add("后天(" + weeks[2] + ")");
                dayList.add("大后天(" + weeks[3] + ")");
            } else if (curWeek.equals("星期一")) {
                dayList.add("明天(" + weeks[2] + ")");
                dayList.add("后天(" + weeks[3] + ")");
                dayList.add("大后天(" + weeks[4] + ")");
            } else if (curWeek.equals("星期二")) {
                dayList.add("明天(" + weeks[3] + ")");
                dayList.add("后天(" + weeks[4] + ")");
                dayList.add("大后天(" + weeks[5] + ")");
            } else if (curWeek.equals("星期三")) {
                dayList.add("明天(" + weeks[4] + ")");
                dayList.add("后天(" + weeks[5] + ")");
                dayList.add("大后天(" + weeks[6] + ")");
            } else if (curWeek.equals("星期四")) {
                dayList.add("明天(" + weeks[5] + ")");
                dayList.add("后天(" + weeks[6] + ")");
                dayList.add("大后天(" + weeks[0] + ")");
            } else if (curWeek.equals("星期五")) {
                dayList.add("明天(" + weeks[6] + ")");
                dayList.add("后天(" + weeks[0] + ")");
                dayList.add("大后天(" + weeks[1] + ")");
            } else if (curWeek.equals("星期六")) {
                dayList.add("明天(" + weeks[0] + ")");
                dayList.add("后天(" + weeks[1] + ")");
                dayList.add("大后天(" + weeks[2] + ")");
            }
        } else {
            if (curWeek.equals("星期日")) {
                dayList.add("今天(" + weeks[0] + ")");
                dayList.add("明天(" + weeks[1] + ")");
                dayList.add("后天(" + weeks[2] + ")");
            } else if (curWeek.equals("星期一")) {
                dayList.add("今天(" + weeks[1] + ")");
                dayList.add("明天(" + weeks[2] + ")");
                dayList.add("后天(" + weeks[3] + ")");
            } else if (curWeek.equals("星期二")) {
                dayList.add("今天(" + weeks[2] + ")");
                dayList.add("明天(" + weeks[3] + ")");
                dayList.add("后天(" + weeks[4] + ")");
            } else if (curWeek.equals("星期三")) {
                dayList.add("今天(" + weeks[3] + ")");
                dayList.add("明天(" + weeks[4] + ")");
                dayList.add("后天(" + weeks[5] + ")");
            } else if (curWeek.equals("星期四")) {
                dayList.add("今天(" + weeks[4] + ")");
                dayList.add("明天(" + weeks[5] + ")");
                dayList.add("后天(" + weeks[6] + ")");
            } else if (curWeek.equals("星期五")) {
                dayList.add("今天(" + weeks[5] + ")");
                dayList.add("明天(" + weeks[6] + ")");
                dayList.add("后天(" + weeks[0] + ")");
            } else if (curWeek.equals("星期六")) {
                dayList.add("今天(" + weeks[6] + ")");
                dayList.add("明天(" + weeks[0] + ")");
                dayList.add("后天(" + weeks[1] + ")");
            }
        }
        if (Integer.parseInt(curTime) <= 6 && Integer.parseInt(curTime) >= 0) {
            timeList.add(times[0]);
            timeList.add(times[1]);
            timeList.add(times[2]);
            timeList.add(times[3]);
            timeList.add(times[4]);
            timeList.add(times[5]);
        } else if (curTime.equals("07") || curTime.equals("08")) {
            timeList.add(times[1]);
            timeList.add(times[2]);
            timeList.add(times[3]);
            timeList.add(times[4]);
            timeList.add(times[5]);
        } else if (curTime.equals("09") || curTime.equals("10")) {
            timeList.add(times[2]);
            timeList.add(times[3]);
            timeList.add(times[4]);
            timeList.add(times[5]);
        } else if (curTime.equals("11") || curTime.equals("12")) {
            timeList.add(times[3]);
            timeList.add(times[4]);
            timeList.add(times[5]);
        } else if (curTime.equals("13") || curTime.equals("14")) {
            timeList.add(times[4]);
            timeList.add(times[5]);
        } else if (curTime.equals("15") || curTime.equals("16")) {
            timeList.add(times[5]);
        }
        UrgentDayAdpter dayAdapter = new UrgentDayAdpter(AtOneBuyActivity.this, dayList);
        urgent_day.setAdapter(dayAdapter);
        latertimeList.add(times[0]);
        latertimeList.add(times[1]);
        latertimeList.add(times[2]);
        latertimeList.add(times[3]);
        latertimeList.add(times[4]);
        latertimeList.add(times[5]);

        if (Integer.parseInt(curTime) >= 16) {
            UrgentTimeAdpter newadapter = new UrgentTimeAdpter(AtOneBuyActivity.this, latertimeList);
            urgent_hour.setAdapter(newadapter);
            urgent_hour.setOnItemClickListener(Onelistener);
        } else {
            UrgentTimeAdpter timeAdapter = new UrgentTimeAdpter(AtOneBuyActivity.this, timeList);
            urgent_hour.setAdapter(timeAdapter);
            urgent_hour.setOnItemClickListener(Onelistener);
        }
        urgent_day.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (Integer.parseInt(curTime) >= 16) {
                    if (i == 0) {
                        UrgentTimeAdpter timeAdapter = new UrgentTimeAdpter(AtOneBuyActivity.this, latertimeList);
                        urgent_hour.setAdapter(timeAdapter);
                        urgent_hour.setOnItemClickListener(Onelistener);
                    } else if (i == 1) {
                        UrgentTimeAdpter timeAdapter = new UrgentTimeAdpter(AtOneBuyActivity.this, latertimeList);
                        urgent_hour.setAdapter(timeAdapter);
                        urgent_hour.setOnItemClickListener(Twolistener);
                    } else if (i == 2) {
                        UrgentTimeAdpter timeAdapter = new UrgentTimeAdpter(AtOneBuyActivity.this, latertimeList);
                        urgent_hour.setAdapter(timeAdapter);
                        urgent_hour.setOnItemClickListener(Threelistener);
                    }
                } else {
                    if (i == 0) {
                        UrgentTimeAdpter tone = new UrgentTimeAdpter(AtOneBuyActivity.this, timeList);
                        urgent_hour.setAdapter(tone);
                        urgent_hour.setOnItemClickListener(Onelistener);
                    } else if (i == 1) {
                        UrgentTimeAdpter ttwo = new UrgentTimeAdpter(AtOneBuyActivity.this, latertimeList);
                        urgent_hour.setAdapter(ttwo);
                        urgent_hour.setOnItemClickListener(Twolistener);
                    } else if (i == 2) {
                        UrgentTimeAdpter tthree = new UrgentTimeAdpter(AtOneBuyActivity.this, latertimeList);
                        urgent_hour.setAdapter(tthree);
                        urgent_hour.setOnItemClickListener(Threelistener);
                    }
                }


            }
        });


    }

    public AdapterView.OnItemClickListener Onelistener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (Integer.parseInt(curTime) >= 16) { //选择明天(当前是明天)
                toTime.setText("送达时间:" + dayList.get(0) + " " + latertimeList.get(i));
                String t[] = latertimeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(2, seHour);//计算邮费
            } else { //选择今天
                toTime.setText("送达时间:" + dayList.get(0) + " " + timeList.get(i));
                String t[] = timeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(1, seHour);//计算邮费
            }

        }
    };


    public AdapterView.OnItemClickListener Twolistener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (Integer.parseInt(curTime) >= 16) {//选择明天(当前是明天)
                toTime.setText("送达时间:" + dayList.get(1) + " " + latertimeList.get(i));
                String t[] = latertimeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(3, seHour);//计算邮费
            } else {//选择明天
                toTime.setText("送达时间:" + dayList.get(1) + " " + latertimeList.get(i));
                String t[] = latertimeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(2, seHour);//计算邮费
            }

        }
    };

    public AdapterView.OnItemClickListener Threelistener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (Integer.parseInt(curTime) >= 16) { //选择大后天(当前是明天)
                toTime.setText("送达时间:" + dayList.get(2) + " " + latertimeList.get(i));
                String t[] = latertimeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(4, seHour);//计算邮费
            } else {                              //选择后天
                toTime.setText("送达时间:" + dayList.get(2) + " " + latertimeList.get(i));
                String t[] = latertimeList.get(i).split(":00-");
                seHour = t[0];
                toaddPostage(3, seHour);//计算邮费
            }


        }
    };


    private void toaddPostage(final int index, final String hour) {
        OkUtilCallback callback = new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                Gson gson = new Gson();
                Entity result = gson.fromJson(response, Entity.class);
                if (result.getResult().equals("OK")) {
                    tdialog.dismiss();
                    postageMoney = (NetUtils.setDecimal(AppConfig.SP_PRICE1 * AppConfig.TEMP + result.getUrgentAmount()));
                    vipMoney.setText("加急邮费: ￥" + NetUtils.setDecimal(result.getUrgentAmount()) + "元");
                    totalAccount.setText(postageMoney);
                    ispost = NetUtils.setDecimal(result.getUrgentAmount());
                } else {
                    TipsToast.makeText(AtOneBuyActivity.this, result.getResult(), TipsToast.LENGTH_SHORT).show();
                    ispost = "";
                    vipMoney.setText("加急邮费: ￥" + "0.0元");
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                ispost = "";
                vipMoney.setText("加急邮费: ￥" + "0.0元");
                TipsToast.makeText(AtOneBuyActivity.this, "系统异常,请稍候再试", TipsToast.LENGTH_SHORT).show();
            }
        };
        String params;
        if (index == 1) {
            params = "areaIds=" + refId + "&date=" + seleDay + "&hour=" + hour;
            seDay = seleDay;
        } else if (index == 2) {
            params = "areaIds=" + refId + "&date=" + tomorrow + "&hour=" + hour;
            seDay = tomorrow;
        } else if (index == 4) {
            params = "areaIds=" + refId + "&date=" + afterTomorrow + "&hour=" + hour;
            seDay = afterTomorrow;
        } else {
            params = "areaIds=" + refId + "&date=" + acquired + "&hour=" + hour;
            seDay = acquired;
        }
        OKUtilAPI.post(OKUtilAPI.countStamp, params, callback);
    }

    //获取用户优惠券
    private void toShowCoupon() {
        final OkUtilCallback okUtilCallback = new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                TLog.log(response);
                CouponsEntity entity = gson.fromJson(response, CouponsEntity.class);
                if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                    BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                } else {
                    couponsList = entity.getList();
                    if (couponsList.size() == 0) {
                        BaseApplication.showToast(R.string.no_coupon);
                    } else {
                        final Dialog dialog = new Dialog(AtOneBuyActivity.this, R.style.Transparent);
                        dialog.setContentView(R.layout.coupon_bottom_dialog);
                        TextView close = (TextView) dialog.findViewById(R.id.close);

                        close.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                            }
                        });
                        dialog.setCanceledOnTouchOutside(true);
                        Coupons coupon = new Coupons();
                        coupon.setId(0);
                        coupon.setName(BaseApplication.resources().getString(R.string.no_use_coupon));
                        couponsList.add(coupon);

                        final ListView listView = (ListView) dialog.findViewById(R.id.listview);
                        listView.setAdapter(new BaseAdapter() {
                            @Override
                            public int getCount() {
                                return couponsList.size();
                            }

                            @Override
                            public Object getItem(int position) {
                                return couponsList.get(position);
                            }

                            @Override
                            public long getItemId(int position) {
                                return position;
                            }

                            @Override
                            public View getView(final int position, View convertView, ViewGroup parent) {
                                convertView = LayoutInflater.from(AtOneBuyActivity.this).inflate(R.layout.coupon_item, null);
                                TextView couponName = (TextView) convertView.findViewById(R.id.couponName);
                                CheckBox couponImg = (CheckBox) convertView.findViewById(R.id.couponImg);
                                couponName.setText(couponsList.get(position).getName());
                                couponImg.setChecked(couponsList.get(position).mChecked);
                                couponImg.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        couponId = couponsList.get(position).getId();

                                        for (int i = 0; i < couponsList.size(); i++) {
                                            couponsList.get(i).setmChecked(false);
                                        }
                                        couponsList.get(position).setmChecked(true);
                                        ((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
                                    }
                                });
                                return convertView;
                            }
                        });
                        Window win = dialog.getWindow();
                        win.setGravity(Gravity.BOTTOM);
                        win.getDecorView().setPadding(0, 0, 0, 0);
                        WindowManager.LayoutParams lp = win.getAttributes();
                        lp.width = WindowManager.LayoutParams.FILL_PARENT;
                        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
                        lp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
                        lp.dimAmount = 0.5f;
                        win.setAttributes(lp);
                        dialog.show();
                    }
                }
            }
        };
        OKUtilAPI.post(OKUtilAPI.getCoupons, "userId=" + userId + "&type=0" + "&st=0", okUtilCallback);
    }

    /**
     * 添加完收货地址后
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == REQ_CODE) {
                mAccpetNone.setVisibility(View.GONE);
                mAcceptLinearlayout.setVisibility(View.VISIBLE);
                System.out.println("地址名" + data.getStringExtra("name"));
                accepterTextView.setVisibility(View.VISIBLE);
                telTextView.setVisibility(View.VISIBLE);
                accepterTextView.setText(data.getStringExtra("name"));
//                     Log.e("BBBB","NAME ===== "+data.getStringExtra("name"));
                telTextView.setText(data.getStringExtra("phone"));
                addressTextView.setText(data.getStringExtra("address"));
                vip.setChecked(false);
                refId = data.getStringExtra("refId");
                toTime.setText("送达时间:");
                vipMoney.setText("加急邮费:");
                postageMoney = (NetUtils.setDecimal(AppConfig.SP_PRICE1 * AppConfig.TEMP));
                totalAccount.setText(postageMoney);
            }
        }
    }

    /**
     * 提交订单请求
     */
    private void commitOrder() {
        final OkUtilCallback okUtilCallback = new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                TLog.log(getActivityTag(), response);
                UserData entity = gson.fromJson(response, UserData.class);
                if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult())) && entity.getLogin()) {
                    mEmptyLayout.setErrorType(EmptyLayout.NO_LOGIN);
                } else if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                    BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                } else if ((AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                    String autoStr = entity.getAuth();
                    if (AppConfig.unAuth.equalsIgnoreCase(autoStr) || AppConfig.authFail.equalsIgnoreCase(autoStr)) {
                        if (TDevice.isTablet(getApplicationContext())) {
                            iDCardDevice = new publicSecurityIDCardLib(AtOneBuyActivity.this);
                            iDCardDevice = null;
                            isstop = false;
                            mHandler.sendEmptyMessage(1001);
                            dialog = new Dialog(AtOneBuyActivity.this, R.style.dialog_common);
                            View bv = dialog.findViewById(android.R.id.title);
                            bv.setVisibility(View.GONE);
                            dialog.setContentView(R.layout.dialog_idcard);
                            dialog.setCanceledOnTouchOutside(true);
                            dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
                                @Override
                                public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent event) {
                                    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                                        mHandler.sendEmptyMessage(1002);
                                        isstop = true;
                                        dialog.dismiss();
                                    }
                                    return false;
                                }
                            });
//                            setTr(dialog);
                            dialog.show();
                            }else{
                                dialog = new Dialog(AtOneBuyActivity.this, R.style.dialog_common);
//                        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                                View bv = dialog.findViewById(android.R.id.title);
                                bv.setVisibility(View.GONE);
                                dialog.setContentView(R.layout.authentication);
                                dialog.setCanceledOnTouchOutside(true);
                                dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
                                    @Override
                                    public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent event) {
                                        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
//                                    if (TDevice.isTablet(getApplicationContext())) {
//                                        mHandler.sendEmptyMessage(1002);
//                                        isstop = true;
//                                    }
                                            dialog.dismiss();
                                        }
                                        return false;
                                    }
                                });
                                TextView whyTextView = (TextView) dialog.findViewById(R.id.whyTextView);
                                whyTextView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
                                nameEdit = (EditText) dialog.findViewById(R.id.nameEdit);
                                idCardEdit = (EditText) dialog.findViewById(R.id.idCardEdit);
                                TextView cancelTV = (TextView) dialog.findViewById(R.id.cancelTV);
                                TextView commit = (TextView) dialog.findViewById(R.id.commit);
//                        if (TDevice.isTablet(getApplicationContext())) {
//                            BaseApplication.showToast("请刷身份证。。。");
//                            nameEdit.setEnabled(false);
//                            idCardEdit.setEnabled(false);
//                            nameEdit.setInputType(InputType.TYPE_NULL);
//                            idCardEdit.setInputType(InputType.TYPE_NULL);
//                            iDCardDevice = new publicSecurityIDCardLib(AtOneBuyActivity.this);
//                            iDCardDevice = null;
//                            isstop = false;
//                            mHandler.sendEmptyMessage(1001);
//                        }

                                cancelTV.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
//                                if (TDevice.isTablet(getApplicationContext())) {
//                                    mHandler.sendEmptyMessage(1002);
//                                    isstop = true;
//                                }
                                        dialog.dismiss();
                                    }
                                });

                                commit.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {

                                        if (StringUtils.isEmpty(nameEdit.getText().toString())) {
                                            BaseApplication.showToast(R.string.names_none);
                                            return;
                                        }
                                        if (StringUtils.isEmpty(idCardEdit.getText().toString())) {
                                            BaseApplication.showToast(R.string.id_card_none);
                                            return;
                                        }
                                        commitAuthRequest(nameEdit.getText().toString(), idCardEdit.getText().toString(), dialog);
                                    }
                                });
                                dialog.show();
                                final Dialog callDialog = new Dialog(AtOneBuyActivity.this, R.style.dialog_common);
//                        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                                View bv1 = callDialog.findViewById(android.R.id.title);
                                bv1.setVisibility(View.GONE);
//                        callDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                                callDialog.setContentView(R.layout.wht_auth);
//                        TextView callTV = (TextView) callDialog.findViewById(R.id.call);
//                        callTV.setOnClickListener(new View.OnClickListener() {
//                            public void onClick(View v) {
//
//                            }
//                        });
                                ImageView deleteCall = (ImageView) callDialog.findViewById(R.id.delete_icon);
                                deleteCall.setOnClickListener(new View.OnClickListener() {
                                    public void onClick(View v) {
                                        callDialog.dismiss();
                                    }
                                });

                                callDialog.setCanceledOnTouchOutside(true);
                                whyTextView.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        callDialog.show();
                                    }
                                });
                            }
                        } else {
                            commitOrderRequest();
                        }
                    }
                }
            }

            ;

            String userId = SPUtils.getStringData(this, SPUtils.USERID);
            OKUtilAPI.post(OKUtilAPI.getUser,"userId="+userId,okUtilCallback);
        }

        Runnable getdata = new Runnable() {
            @Override
            public void run() {
                getIdCardData();
            }
        };

    private void getIdCardData() {
        int ret;
        if (iDCardDevice == null) {
            iDCardDevice = new publicSecurityIDCardLib(mContext);
        }
        ret = iDCardDevice.readBaseMsgToStr(pkName, BmpFile, name, sex, nation, birth, address, IDNo, Department,
                EffectDate, ExpireDate);
        /********************************将图片放到textview里边显示****************************/
//		int[] colors =iDCardDevice.convertByteToColor(BmpFile);
//		b = Bitmap.createBitmap(colors, 102, 126, Bitmap.Config.ARGB_8888);
//		ImageSpan imgSpan = new ImageSpan(b);
//		SpannableString spanString = new SpannableString("icon");
//		spanString.setSpan(imgSpan, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        /**************************************************************************************/
        System.out.println("ret == " + ret);
        if (ret == 0x90) {
            mHandler.sendEmptyMessage(1002);
            int[] colors = iDCardDevice.convertByteToColor(BmpFile);
//                b = Bitmap.createBitmap(colors, 102, 126, Bitmap.Config.ARGB_8888);
//                names = new String(name, "Unicode");
//                sexs = new String(sex, "Unicode");
//                nations = new String(nation, "Unicode");
//                births = new String(birth, "Unicode");
//                addr = new String(address, "Unicode");
//                IDNos = new String(IDNo, "Unicode");
//                departments = new String(Department, "Unicode");
//                effectDates = new String(EffectDate, "Unicode");
//                departments = departments.replace(" ", "");
//                names = names.replace(" ", "");
//                sexs = sexs.replaceAll("[^\\u4e00-\\u9fa5]", "");
//                nations = nations.replaceAll("[^\\u4e00-\\u9fa5]", "");
//                addr = addr.replace(" ", "");
//                expireDates = new String(ExpireDate, "Unicode");
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (dialog.isShowing()) {
                            dialog.dismiss();
                        }
                        final Dialog dialog1 = new Dialog(AtOneBuyActivity.this, R.style.dialog_common);
//                        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                        View bv = dialog1.findViewById(android.R.id.title);
                        bv.setVisibility(View.GONE);
                        dialog1.setContentView(R.layout.dialog_idcard_show);
                        dialog1.setCanceledOnTouchOutside(true);
                        dialog1.setOnKeyListener(new DialogInterface.OnKeyListener() {
                            @Override
                            public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent event) {
                                if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                                    dialog1.dismiss();
                                }
                                return false;
                            }
                        });
//                        setTr(dialog1);
                        final TextView textView1 = (TextView) dialog1.findViewById(R.id.tv_name);
                        TextView textView2 = (TextView) dialog1.findViewById(R.id.tv_sex);
                        TextView textView3 = (TextView) dialog1.findViewById(R.id.tv_bir);
                        final TextView textView4 = (TextView) dialog1.findViewById(R.id.tv_idcard);
                        TextView textView5 = (TextView) dialog1.findViewById(R.id.tv_que);
                        textView5.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                try {
                                    commitAuthRequest(new String(name, "Unicode"), new String(IDNo, "Unicode"), dialog1);
                                } catch (UnsupportedEncodingException e) {
                                    e.printStackTrace();
                                }
                            }
                        });
                        textView1.setText("姓名：" + new String(name, "Unicode"));
                        textView2.setText("性别：" + new String(sex, "Unicode"));
                        textView3.setText("出生日期：" + new String(birth, "Unicode"));
                        textView4.setText("身份证号：" + new String(IDNo, "Unicode"));
                        dialog1.show();
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                }
            });
//				show = "姓名:"+new String(name, "Unicode")+'\n'
//						+"性别:"+new String(sex, "Unicode")+'\n'
//						+"民族:"+ new String(nation, "Unicode")+"族"+'\n'
//						+"出生日期:"+new String(birth, "Unicode")+'\n'
//						+"住址:"+new String(address, "Unicode")+'\n'
//						+"身份证号码:"+new String(IDNo, "Unicode")+'\n'
//						+"签发机关:"+new String(Department, "Unicode")+'\n'
//						+"有效日期:"+ new String(EffectDate, "Unicode") + "至" + new String(ExpireDate, "Unicode")+'\n';
        } else {
            mHandler.sendEmptyMessage(1001);
//			ToastUtil.ShowToast(mContext,"请将身份证放在识读区",200);
//			show ="读基本信息失败:"+String.format("0x%02x", ret);
        }
//		if(ret==0x90) viewBmp.setText(spanString);  			/*显示头像*/
    }

    /**
     * 提交认证请求
     *
     * @param name
     * @param idcard
     * @param dialog2
     */
    private void commitAuthRequest(String name, String idcard, final Dialog dialog2) {
        final OkUtilCallback okUtilCallback = new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                hideWaitDialog();
                TLog.log(getActivityTag(), response);
                Entity entity = gson.fromJson(response, Entity.class);
                if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult())) && entity.getLogin()) {
                    mEmptyLayout.setErrorType(EmptyLayout.NO_LOGIN);
                } else if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                    BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                } else if ((AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                    BaseApplication.showToast(R.string.auth_commit_success);
                    if (dialog2 != null && dialog2.isShowing()) dialog2.dismiss();
                }
            }
        };
        showWaitDialog(BaseApplication.getIntstance().getString(R.string.auth_commiting));
        String userId = SPUtils.getStringData(AtOneBuyActivity.this, SPUtils.USERID);
        int ifATM = 0;
        if (TDevice.isTablet(getApplicationContext())) {
            ifATM = 1;//是ATM验证
        } else {
            ifATM = 0;
        }
        OKUtilAPI.post(OKUtilAPI.saveNameAuth, "userId=" + userId + "&name=" + name + "&idcard=" + idcard + "&ifATM=" + ifATM, okUtilCallback);
    }

    /*
    *
    * 立即生成订单
    */
    private void commitOrderRequest() {

//       if(settleAccountsEntity.getCoupons().size()<=1){
//           BaseApplication.showToast(R.string.no_coupon);
//       }
        showWaitDialog("正在提交");
        String remarks = mBuyerTips.getText().toString();
        String userId = SPUtils.getStringData(AtOneBuyActivity.this, SPUtils.USERID);
        String quickUrl = "";
        if (vip.isChecked() == false) {
            quickUrl = OKUtilAPI.QUICK + "?userId=" + userId + "&goodsId=" + id + "&num=" + AppConfig.TEMP + "&remarks=" + remarks + "&addrId=" + AppConfig.CITY_ID;
        } else if (vip.isChecked() == true) {
            quickUrl = OKUtilAPI.QUICK + "?userId=" + userId + "&goodsId=" + id + "&num=" + AppConfig.TEMP + "&remarks=" + remarks + "&addrId=" + AppConfig.CITY_ID + "&date=" + seDay + "&hour=" + seHour;
        }
        if(TDevice.isTablet(AtOneBuyActivity.this)){
            quickUrl = quickUrl + "&deviceType=ATM";
        }
        Log.i("aaa", "----url---" + quickUrl);
        if (!NetUtils.isConnected(this)) {
            Toast.makeText(AtOneBuyActivity.this, "请检查你的网络", Toast.LENGTH_SHORT).show();
        } else {
            JsonHttpNet.dataDownNet(quickUrl, new JsonHttpNet.HttpCallbackListener() {
                @Override
                public void onFinish(String response) {
                    Log.e("result", "response---------=======" + response);
                    Entity entity = gson.fromJson(response, Entity.class);
                    if (AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult())) {
                        AppConfig.isRefreshShocpar = true;
                        Intent intent = new Intent(AtOneBuyActivity.this, PayActivity.class);
                        intent.putExtra("orderNo", entity.getOrderNo());
                        intent.putExtra("goodsName", goodname);
//                        if(TextUtils.isEmpty(ispost)){
//                            intent.putExtra("goodsCurPrice",Double.valueOf(NetUtils.setDecimal(settleAccountsEntity.getShopcar().getAmount())));
//                        }else if(!TextUtils.isEmpty(postageMoney)){
//                        }
                        intent.putExtra("goodsCurPrice", Double.valueOf(postageMoney));
                        startActivity(intent);
                        hideWaitDialog();
                        finish();
                    } else {
                        Toast.makeText(AtOneBuyActivity.this, entity.getResult(), Toast.LENGTH_SHORT).show();
                        hideWaitDialog();
                    }
                }

                @Override
                public void onError(Exception e) {

                }
            });
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        isstop = true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        isstop = false;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (TDevice.isTablet(getApplicationContext())) {
            mHandler.removeCallbacks(getdata);
            mHandler.removeCallbacksAndMessages(null);
        }
    }
//    public void setTr(Dialog d){
//        try {
//            Context context = d.getContext();
//            int dividerID = context.getResources().getIdentifier("android:id/titleDivider", null, null);
//            View divider = findViewById(dividerID);
//            divider.setBackgroundColor(Color.TRANSPARENT);
//        } catch (Exception e) {
//            //上面的代码，是用来去除Holo主题的蓝色线条
//            e.printStackTrace(); 		}
//    }
}

